﻿using System;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Validation;
using System.Globalization;
using System.Linq;
using System.Text;
using SH.Model;

namespace SH.DataAccess
{
    public class ModelContainer : DbContext
    {
        public ModelContainer()
            : base("name=ModelContainer")
        {
        }
        
        //public override int SaveChanges()
        //{
        //    var r = -1;
            
        //    try
        //    {
        //        r = base.SaveChanges();
        //    }
        //    catch (DbEntityValidationException ex)
        //    {
        //        foreach (var failure in ex.EntityValidationErrors)
        //        {
        //            var entityException = new EntityExceptions(failure.Entry.Entity.GetType());
        //            foreach (var error in failure.ValidationErrors)
        //            {
        //                entityException.Exceptions.Add(new Exception(error.ErrorMessage));
        //            }
        //            throw entityException;
        //        }
        //    }
            
        //    return r;
        //}
          
        
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //throw new UnintentionalCodeFirstException();
        }

        public string GetResourceString(string name, IFormatProvider culture = null)
        {
            if (culture == null)
                culture = (IFormatProvider)CultureInfo.CurrentCulture;
            return string.Format(culture, name);
        }

        public string GetResourceString(string name, Type culture)
        {

            throw new NotImplementedException();
        }

        public DbSet<Storehause> Storehauses { get; set; }
        public DbSet<Certificate> Certificates { get; set; }
        public DbSet<Status> Statuses { get; set; }
        public DbSet<Region> Regions { get; set; }
    }
}
